package com.example.springaitest.controller;

import com.example.springaitest.repository.ChatHistoryRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RequiredArgsConstructor
@RestController
@RequestMapping("/ai")
public class GameController {

    final ChatClient gameChatClient;

    //流式调用
    @GetMapping(value = "/game",produces = "text/html;charset=utf-8")
    public Flux<String> chat_stream(@RequestParam("prompt") String message,@RequestParam("chatId") String chatId){
        System.out.println(message);
        return gameChatClient.prompt()
                .user(message)
                .advisors(a->a.param(AbstractChatMemoryAdvisor.CHAT_MEMORY_CONVERSATION_ID_KEY,chatId))
                .stream()
                .content();
    }}
